#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);

    //设置LineEdit的echoMode
    ui->lineEdit->setEchoMode(QLineEdit::Password);

    //创建两个图标对象
    isVisible = new QIcon(":/image/isVisible.png");
    visible = new QIcon(":/image/visible.png");

    //给pushButton设置图片
    ui->pushButton->setIcon(*isVisible);

}

Widget::~Widget()
{
    //手动释放图标对象
    delete isVisible;
    delete visible;
    delete ui;
}


void Widget::on_pushButton_pressed()
{
    //当按下按钮时，设置按钮的图标为可见
    ui->pushButton->setIcon(*visible);

    ui->lineEdit->setEchoMode(QLineEdit::Normal);
}

void Widget::on_pushButton_released()
{
    //当抬起按钮时，设置按钮的图标为不可见
    ui->pushButton->setIcon(*isVisible);

    ui->lineEdit->setEchoMode(QLineEdit::Password);
}
